<?php

namespace App\Http\Controllers;

use App\Util\Tool;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Redis;

class DestructionController extends BaseController
{
    /**
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function destruction(Request $request)
    {
        //检查token是否存在
        if (Tool::GetLoginToken($request->api_token)) {
            //获取用户信息
            $user = Tool::ApiTokenGetDoctorUser($request->api_token);
            //检查是否登录
            if (empty($user)) {
                return $this->ResultJson(0, '请先登录后再操作!', []);
            }
            $user->state = 3; //设置注销
            $user->online = 0;//设置离线
            $user->save();
            Redis::del($request->api_token);
            return $this->ResultJson(1, '注销成功', []);
        }
        return $this->ResultJson(0, '注销失败!', []);
    }
}
